//
//  UIView+SLAnimation.m
//  UIViewCatelogTest
//
//  Created by WSL on 15/10/13.
//  Copyright © 2015年 WSL. All rights reserved.
//

#import "UIView+SLAnimation.h"




@implementation UIView (SLAnimation)

- (void) addAnimation:(AnimationType) animationType{
    if (animationType == AnimationSpringType) {
        CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
        
        animation.duration = 0.5;
        animation.values = @[@1.0 ,@1.4 ,@0.9 ,@1.15 ,@0.95 ,@1.02 ,@1.0 ];
        animation.calculationMode = kCAAnimationCubic;
        
        [self.layer addAnimation:animation forKey:@"transform.scale"];
    }
    
    if (animationType == AnimationScaleType) {
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        
        animation.fromValue = @1;
        animation.toValue = @1.5;
        animation.duration = 0.3;
        animation.autoreverses = YES;
        [self.layer addAnimation:animation forKey:@"transform.scale"];
    }
    
    if (animationType == AnimationNone) {
        return ;
    }
    
    if (animationType == AnimationOpacity) {
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
        
        animation.fromValue = @0;
        animation.toValue = @1;
        animation.duration = 0.3;
        animation.autoreverses = YES;
        [self.layer addAnimation:animation forKey:@"opacity"];
        self.layer.opacity = 1;
    }
    if (animationType == AnimationTransformYSpring) {
        
        CABasicAnimation *animationY = [CABasicAnimation animationWithKeyPath:@"position.y"];
        animationY.delegate = self;
        animationY.duration = 0.2;
        animationY.fromValue = @([UIScreen mainScreen].bounds.size.height);
        animationY.toValue = @(self.frame.origin.y+self.frame.size.height/2);
        
        [self.layer addAnimation:animationY forKey:@"position.y"];
        
    }
    
//    if (animationType == AnimationHiddenFromY) {
//        CABasicAnimation *animationY = [CABasicAnimation animationWithKeyPath:@"position.y"];
//        animationY.delegate = self;
//        animationY.duration = 0.2;
//        animationY.fromValue = @(self.frame.origin.y+self.frame.size.height/2);
//        animationY.toValue = @([UIScreen mainScreen].bounds.size.height);
//        
//        animationY.removedOnCompletion = NO;
//        [self.layer addAnimation:animationY forKey:@"position.y"];
//    }

}

@end
